package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletConfig;
import java.util.Date;

/**
 * @author lixu
 */
//@Controller
@RequestMapping("/json")
//@ResponseBody  //全局  当前类所有方法 返回的数据都要进行JSON转换
@RestController
public class JsonController {

    /**
     * 接收 json串并转成对象
     *  json:        {"id":123,"name":"小小"}
     *
     *  @RequestBody : 底层 官方推荐 jackson 进行JSON转换
     *
     *                 底层改成阿里巴巴 fastjson  进行JSON转换
     */
    @PostMapping("/send")
    public User send(@RequestBody User user){

        System.out.println("user:" + user);
        user.setId(888);
        user.setName("磊大大");
        user.setBirth(new Date());
        return user;
    }
}
